<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <div class="table-operator" style="border-top: 5px">
        <a-button type="primary" @click="handleAdd">新增</a-button>
      </div>
      <a-table
        ref="table"
        rowKey="id"
        size="middle"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading">
         <span  slot="status" slot-scope="text, record">
           <a-switch :checked="record.status == 1" @click="updateBrandStatus(record,$event ? noChoose: ischoose)"></a-switch>
        </span>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">
            <a-icon type="edit"/>
            编辑
          </a>
          <a-divider type="vertical"/>
          <a-divider type="vertical"/>
          <a-popconfirm title="确定删除吗?" @confirm="() =>handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>
    <bladeQuestions-Modal ref='modalForm' @ok="modalFormOk"></bladeQuestions-Modal>
  </a-card>
</template>

<script>
  import { listBladeQuestions, delBladeQuestions } from "@/api/umbrella/BladeQuestions";
  import { UmbrellaListMixin } from '@/mixins/UmbrellaListMixin'
  import bladeQuestionsModal from '../modules/bladeQuestionsModal'
  import { filterObj } from '@/utils/util';
  import { postAction } from '@/api/manage'
  export default {
    components: {bladeQuestionsModal},
    mixins:[UmbrellaListMixin],
    data() {
      return {
        ischoose: 0,
        noChoose: 1,
        totalPage:0,
        // 表头
        columns: [
          {
            title: '编号',
            dataIndex: '',
            key: 'rowIndex',
            width: 120,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '问题',
            align: "center",
            dataIndex: 'question',
          },
          {
            title: '答案',
            align: "center",
            dataIndex: 'answer',
          },
          {
            title: '是否显示',
            align: "center",
            dataIndex: 'status',
            scopedSlots: {customRender: 'status'},
          },
          {
            title: '创建时间',
            align: "center",
            dataIndex: 'createTime',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: "center",
            scopedSlots: {customRender: 'action'},
          }
        ],
        // 查询参数
        queryParam:{
          current: 1,
          size: 10,
        },
        // 数据 -- 表格
        dataSource:[],
        // loading 是否显示  请求表格列表之前 设置为true   请求结束设置为false
        loading:false,
        url: {
          list: "/api/gateway/jic-backend-activity/BladeQuestions/list",
          delete: "/api/gateway/jic-backend-activity/BladeQuestions/remove",
        },
      };
    },
    created() {
    },
    methods: {
      getQueryParams() {
        var param = Object.assign({}, this.queryParam);
        param.current = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize;
        return filterObj(param);
      },
      // 重置搜索框的内容
      searchReset() {
        var that = this;
        that.loadData(this.ipagination.current);
      },
      updateBrandStatus(row,event){
        let url = "/jic-backend-activity/BladeQuestions/update"
        let params={
          id:row.id,
          status:event,
        }
        postAction(url,params).then(res=>{
          if (res.success) {
            this.$message.success(res.msg)
            this.loadData(this.ipagination.current);
          } else {
            this.$message.warning(res.msg)
          }
        })
      },

    }

  };
</script>